package com.youshang.config;

import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
import com.youshang.annotation.DataMasking;
import com.youshang.model.MaskModel;

public class DataMaskingAnnotationIntrospector extends NopAnnotationIntrospector {

    @Override
    public Object findSerializer(Annotated am) {
        DataMasking annotation = am.getAnnotation(DataMasking.class);
        if (annotation != null) {
            return new DataMaskingSerializer(annotation.maskFunc().operation(), MaskModel
                    .builder()
                    .markChar(annotation.maskChar())
                    .position(annotation.position())
                    .offset(annotation.offset())
                    .build());
        }
        return null;
    }

}